const mongoose = require('mongoose')

const Image = mongoose.model('Image')
const Comment = mongoose.model('Comment')

module.exports = async () =>
  await Promise.all([
    Image.aggregate([{
      $group: {
          _id: 'total',
          images: {$sum: 1},
          views:  {$sum: '$views'},
          likes:  {$sum: '$likes'}
      }
    }]),
    Comment.count()
  ])
    .then( ([docs,commentNum]) => ({
        images: docs[0].images,
        views: docs[0].views,
        likes: docs[0].likes,
        comments: commentNum
    }))
